package com.qf.ems.controller;

import com.qf.ems.entity.Emp;
import com.qf.ems.entity.Page;
import com.qf.ems.service.EmpService;
import com.qf.ems.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/manager/safe/showAllEmp")
public class ShowAllEmpController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 从请求当中获取分页参数信息
        String pageIndex = req.getParameter("pageIndex");//页码
        if(pageIndex == null){
            pageIndex = "1";
        }
        // 创建分页对象
        Page page = new Page(Integer.valueOf(pageIndex));
        // 调用service层的方法，进行分页数据查询
        EmpService empService = new EmpServiceImpl();
        List<Emp> emps = empService.showAllEmpByPage(page);
        // 把查询到的数据返回给jsp页面，由jps页面做显示
        req.setAttribute("emps",emps);//把员工数据存放到req对象中，交给jsp页面
        req.setAttribute("page",page);
        req.getRequestDispatcher("/emplist.jsp").forward(req,resp);
    }
}
